<%-- 
  - Author: Neha Chauhan
  - Date: 25-Mar-2011
  - Copyright Notice: TRAKHEES
  - Description: form.jsp
 --%>

<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ page import="ae.pcfc.etks.online.web.*"%>

<c:choose>
	<c:when
		test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-ar.js"/>'></script>
	</c:when>
	<c:otherwise>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-en.js"/>'></script>
	</c:otherwise>
</c:choose>

<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/jquery.jqGrid.min.js"/>'></script>

<!-- jQuery Date Picker Arabic Locale -->
<c:if
	test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
	<script language="Javascript"
		src='<c:url value="/resources/js/ui/jquery.ui.datepicker-ar.js"/>'></script>
</c:if>


<script type="text/javascript">
	$()
			.ready(
					function() {

						//$("input:submit, input:reset, input:button, input:file").button();
						$("input[name=strDefaultService]").change(function(){
							var defaultService = $("input[name=strDefaultService]:checked");
							if(defaultService.length > 0){
								$(".forDefaultService").hide();
							}else{
								$(".forDefaultService").show();
							}
						});
						$("input[name=strDefaultService]").trigger('change');
						$("input[name=strServiceType]").change(function(){
							if($(this).val() == 'I'){
								$(".forExternalService").hide();
							}else{
								$(".forExternalService").show();
								$("input[name=strDefaultService]").trigger('change');
							}
						});
						$("input[name=strServiceType]").trigger('change');
						//strDefaultService
						
						
						$("#RegisterService")
								.validate(
										{
											onfocusout : false,
											onkeyup : false,
											onclick : false,
											rules : {
												strServiceNameEng : "required",
												strServiceNameArb : "required"/*,
												strServiceOwner : "required",
												arrServiceRole : "required"*/
											},

											showErrors : function(errorMap,
													errorList) {

												var errors = '<ul>';
												var label;
												if (errorList.length) {
													$.each(errorMap, function(
															name, value) {
														label = $(
																"label[for='"
																		+ name
																		+ "']")
																.html();
														label = value + '['
																+ label + ']';
														errors = errors
																+ '<li>'
																+ label
																+ '</li>';

													});
													errors = errors + '</ul>';
													jAlert('error', errors,
															'<spring:message code="label.errormessage" />');
												}
											}

										});
						 $("#strDefaultService1").click(function()
						 {
						  	if($(this).val() == 'Y')
						  	{
								
						 	}

						 });
					});
	
	function del(row) 
	{		
		document.getElementById('row').value = row;	
			
	}
</script>

<div id="container" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>'>


	<form:form name="RegisterService" id="RegisterService" method="POST"
		modelAttribute="<%=ConstantsAdmin.ADMIN_REGISTER_SERVICE_MODEL_KEY %>">


		<spring:hasBindErrors
			name="<%=ConstantsAdmin.ADMIN_REGISTER_SERVICE_MODEL_KEY %>">
			<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'error',
											'<li><form:errors path="*" delimiter="<li>"/>',
											'<spring:message code="label.errormessage" />');
								});
			</script>
		</spring:hasBindErrors>
		
		<%
					if(request.getAttribute(ConstantsAdmin.SUCCESS_PARAM) != null) {
				%>
		<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'success','<%=request.getAttribute(ConstantsAdmin.SUCCESS_PARAM)%>',
											'<spring:message code="msg.success" />');
								});
			</script>			
		<% }  %>
	<div class="t_form">
		<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix"><spring:message code="label.service.define" /></div>
       	<div class="t_fin-black-txt ">
			
	<fieldset>
			<legend><spring:message code="label.service" /></legend>
	</fieldset>			
			
			<div class="t_form-left">
				<div>
				<form:label path="strServiceNameEng">
					<span class="t_star">*</span>
					<spring:message code="label.servicename.eng" />
				</form:label>
				<form:input path="strServiceNameEng" id="strServiceNameEng"
					name="strServiceNameEng" size="20" maxlength="100"  class="t_form-fld-disable"/>
			</div>

			<div>
				<form:label path="strServiceNameArb">
					<span class="t_star">*</span>
					<spring:message code="label.servicename.arb" />
				</form:label>
				<form:input path="strServiceNameArb" id="strServiceNameArb"
					name="strServiceNameArb" size="20" maxlength="100" class="t_form-fld-disable"/>
			</div>
			<div>
				<form:label path="strServiceType">
					<span class="t_star">*</span><spring:message code="label.service.type" />
				</form:label>
				<c:forEach items="${adminServiceTypeList}" var="type">
					<c:out value="${type.displayLabel}"></c:out>
					<form:radiobutton path="strServiceType" class="opt-input" value="${type.id}"/>
				</c:forEach>
			</div>	
			<div class="forExternalService">
				<form:label path="strServiceOwner">
					<span class="t_star">*</span>
					<spring:message code="label.serviceowner" />
				</form:label>
				<c:choose>
					<c:when
						test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
						<form:select path="strServiceOwner"
							items="${adminRegisterServiceOwnerList}" id="strServiceOwner"
							itemLabel="labelAr" itemValue="id" class="fm-opt"/>
					</c:when>
					<c:otherwise>
						<form:select path="strServiceOwner"
							items="${adminRegisterServiceOwnerList}" id="strServiceOwner"
							itemLabel="labelEn" itemValue="id" class="fm-opt"/>
					</c:otherwise>
				</c:choose>
			</div>
			<div class="forExternalService">
				<form:label path="arrServiceDeptsCode"><spring:message code="label.service.dept" /></form:label>				
				<c:choose>
					<c:when
						test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
						<form:select path="arrServiceDeptsCode"
							items="${adminRegisterServiceOwnerList}"
							id="arrServiceDeptsCode" itemLabel="labelAr" itemValue="id" class="fm-opt" style="height:100px;" multiple="true"/>
					</c:when>
					<c:otherwise>
						<form:select path="arrServiceDeptsCode"
							items="${adminRegisterServiceOwnerList}"
							id="arrServiceDeptsCode" itemLabel="labelEn" itemValue="id"  class="fm-opt" style="height:100px;" multiple="true"/>
					</c:otherwise>
				</c:choose>
			</div>
			<div class="forExternalService">
				<form:label path="arrServiceRole">
					<span class="t_star">*</span>
					<spring:message code="label.service.role" />
				</form:label>
				<c:choose>
					<c:when
						test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
	
							<form:select id="arrServiceRole" path="arrServiceRole" multiple="true"  class="fm-opt" style="height:100px;">			   		           
						   		           <form:options items="${adminRegisterServiceRolesList}" itemValue="id" itemLabel="labelAr" delimiter="<br/>" />
						    </form:select>
					</c:when>
					<c:otherwise>
						<form:select id="arrServiceRole" path="arrServiceRole" multiple="true"  class="fm-opt" style="height:100px;">			   		           
						   		           <form:options items="${adminRegisterServiceRolesList}" itemValue="id" itemLabel="labelEn" delimiter="<br/>" />
						    </form:select>
					</c:otherwise>
				</c:choose>
			</div>
			<div class="forExternalService">
				<form:label path="strDefaultService"><spring:message code="label.default.service" /></form:label>
				<form:checkbox path="strDefaultService" value="Y" class="opt-input"/>
			</div>
			<div>
				<form:label path="strServiceURL"><spring:message code="label.service.URL" /></form:label>
				<form:input path="strServiceURL" class="t_form-fld-disable"/>
			</div>
			<div>
				<form:label path="strServiceSecRole"><spring:message code="label.service.security.role" /></form:label>
				<form:input path="strServiceSecRole" class="t_form-fld-disable"/>
			</div>
	</div>	
	<div class="forExternalService forDefaultService">		
	<fieldset>
			<legend><spring:message code="label.serviceattributes" /></legend>			
	</fieldset>
			<div class="t_form-left">
				<div>
				<form:label path="strServiceAttributeNameEng">
					<span class="t_star">*</span>
					<spring:message code="label.serviceattributename.eng" />
				</form:label>
				<form:input path="strServiceAttributeNameEng"
					id="strServiceAttributeNameEng" name="strServiceAttributeNameEng"
					size="20" maxlength="100" class="t_form-fld-disable"/>
			</div>

			<div>
				<form:label path="strServiceAttributeNameArb">
					<span class="t_star">*</span>
					<spring:message code="label.serviceattributename.arb" />
				</form:label>
				<form:input path="strServiceAttributeNameArb"
					id="strServiceAttributeNameArb" name="strServiceAttributeNameArb"
					size="20" maxlength="100" class="t_form-fld-disable"/>
			</div>

			<div>
				<form:label path="strNeccessity">
					<span class="t_star">*</span>
					<spring:message code="label.neccessity" />
				</form:label>
				<form:select path="strNeccessity"
					items="${adminRegisterServiceAttributeNeccessityList}"
					id="strNeccessity" itemLabel="displayLabel" itemValue="id" class="fm-opt"/>
			</div>			
			<div id="fm-submit" class="t_btn-container t_btns">
					<input type="submit" name="add" value="<spring:message code="label.button.add" />" class="t_btns submit" />
			</div>
		</div>
				<c:if
					test="${null != adminRegisterService.arrServiceAttributes and not empty adminRegisterService.arrServiceAttributes}">

					<table class="t_grid-table" style="clear:both;">
						<tr class="odd ui-jqgrid-labels">
							<td class="ui-state-default ui-th-column ui-th-ltr"><spring:message
									code="label.serviceattributename.eng" />
							</td>
							<td class="ui-state-default ui-th-column ui-th-ltr"><spring:message
									code="label.serviceattributename.arb" />
							</td>
							<td class="ui-state-default ui-th-column ui-th-ltr"><spring:message
									code="label.neccessity" />
							</td>
							<td class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.edit" />
							</td>
						</tr>
						<c:forEach items="${adminRegisterService.arrServiceAttributes}"
							var="service" varStatus="loop">
							<c:choose>
								<c:when test="${loop.count % 2 == 0}">
									<c:set var="rowStyle" scope="page" value="odd" />
								</c:when>
								<c:otherwise>
									<c:set var="rowStyle" scope="page" value="even" />
								</c:otherwise>
							</c:choose>
							<tr class="${rowStyle}">
								<td><c:out value="${service.strServiceAttributeNameENG}" />
								</td>
								<td><c:out value="${service.strServiceAttributeNameARB}" />
								</td>
								<td><c:choose>
										<c:when
											test="${service.strNecessisty == 'M' || service.strNecessisty == 'm'}">
											<spring:message code="label.service.attr.mandatory" />
										</c:when>
										<c:otherwise>
											<spring:message code="label.service.attr.optional" />
										</c:otherwise>
									</c:choose></td>
								<td>
										<input type="submit" name="delete"
											onclick="del('<c:out value="${service.strServiceAttributeNameENG}"/>');"
											value="<spring:message code="label.button.delete" />"
											class="t_btns submit" />
								</td>
							</tr>
						</c:forEach>
					</table>

				</c:if>
		</div>
		<div id="fm-submit">
			<input type="submit" name="save" value="<spring:message code="label.button.save" />" class="t_btns submit"/>			
			<input type="reset" name="reset" value="<spring:message code="label.button.reset" />" class="t_btns reset"/>
		</div>
		
		<c:forEach items="${adminRegisterService.arrServiceAttributes}" var="mapping" varStatus="loop">
                       <form:hidden path="arrServiceAttributes[${loop.index}].strServiceAttributeNameENG" value="${arrServiceAttributes.strServiceAttributeNameENG}"/>
                        <form:hidden path="arrServiceAttributes[${loop.index}].strServiceAttributeNameARB" value="${arrServiceAttributes.strServiceAttributeNameARB}"/>
                        <form:hidden path="arrServiceAttributes[${loop.index}].strNecessisty" value="${arrServiceAttributes.strNecessisty}"/>
                        
         </c:forEach>
         			
		<input type="hidden" name="row" id="row" value="" />	
				
	

		</div>
	</div>
	</form:form>
</div>
